package main

import (
	"fmt"
	"math/rand"
)

//练习4：验证用户名密码是否正确
//var userList = map[string]map[string]string{
//	"root":{"password":"123456", "tel":"158xxxxxxxx"},
//	"admin":{"password":"123456", "tel":"158xxxxxxxx"},
//	"xiaoming":{"password":"123456", "tel":"158xxxxxxxx"}}
//输入用户名密码，进行验证，验证成功后，输出手机号码




//练习2：求两个3*3矩阵的和并输出（数据都是int类型）
//	解析：矩阵的和计算规则是对应元素相加：
//	c[i][j] = a[i][j] + b[i][j]


func main(){





	ex2()
}
//练习2：求两个3*3矩阵的和并输出（数据都是int类型）
//	解析：矩阵的和计算规则是对应元素相加：
//c[i][j] = a[i][j] + b[i][j]
func ex2(){
	var a = [3][3]int{{1,2,3},{4,5,6},{7,8,9}}
	var b = [3][3]int{{9,8,7},{6,5,4},{3,2,1}}
	var c = [3][3]int{}
	for i:=0; i<3; i++{
		for j:=0; j<3; j++{
			c[i][j] = a[i][j] + b[i][j]
		}
	}
	fmt.Println(c)
}



//练习3：使用go编写随机点名系统
//切片类型存放全班同学的名字：["史伟名","易鸽玲"]
//按任意键，不限次数随机抽取切片中的某一个同学名字回答问题
//抽取到的同学就从切片中删除
//按q退出，或者切片里面所有的同学都已近被抽到
func ex3(){
	var namelist = []string{"游淑娟","周雨晴","全妍","夏经纬","杨玉蟾","李家轩"}
	fmt.Println("输入任意键抽取同学回答问题:")
	for i:=1;i>0;i++{
		num := rand.Intn(len(namelist))
		var a string
		fmt.Scan(&a)
		if a!="q"{
			fmt.Println(namelist[num])
		}else{
			break
		}
	}
}



//练习4：验证用户名密码是否正确
//var userList = map[string]map[string]string{
//	"root":{"password":"123456", "tel":"158xxxxxxxx"},
//	"admin":{"password":"123456", "tel":"158xxxxxxxx"},
//	"xiaoming":{"password":"123456", "tel":"158xxxxxxxx"}}
//输入用户名密码，进行验证，验证成功后，输出手机号码

func ex4(){
	var userList = map[string]map[string]string{
		"root":{"password":"123456", "tel":"158xxxxxxxx"},
		"admin":{"password":"123456", "tel":"158xxxxxxxx"},
		"xiaoming":{"password":"123456", "tel":"158xxxxxxxx"}}
	flag := 0
	fmt.Print("please input your username:")
	var username string
	fmt.Scan(&username)
	fmt.Print("please input your password:")
	var password string
	fmt.Scan(&password)
	for k,userinfo := range userList{
		if k == username{
			if userinfo["password"] == password{
				flag = 1
				fmt.Printf("验证成功，您的号码为%s\n",userinfo["tel"])
			}
		}
	}
	if flag ==0 {
		fmt.Println("您的用户名或密码输入错误")
	}

}
